import numpy as np

# 创建一个数组
arr = np.array([[1, 2, 3, 4, 5],
               [1, 2, 3, 4, 5],
               [1, 2, 3, 4, 5]])

# 数组属性
print("ndarray:", arr)               # NumPy 核心数据结构
print("dtype:", arr.dtype)           # 元素类型
print("ndim:", arr.ndim)             # 数组维度数
print("shape:", arr.shape)           # 数组形状
print("size:", arr.size)             # 数组元素总数
print("itemsize:", arr.itemsize)     # 每个元素字节大小
print('==============数组属性====================')

# 数组方法
reshaped = arr.reshape(5, 3)         # 改变形状
print("reshape:", reshaped)
flattened = arr.flatten()            # 展平为一维数组
print("flatten:", flattened)
raveled = arr.ravel()                # 展平视图
print("ravel:", raveled)
transposed = reshaped.transpose()    # 转置
print("transpose:\n", transposed)
print('==============数组方法====================')

# 广播示例
arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
result = arr1 + arr2  # 直接按元素点对点相加
print("broadcasting result:", result)
print('==============广播示例====================')